From c27ad917f234f19717a861491b9c8e9114df2044 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Wed, 12 Oct 2005 09:28:12 +0100 Subject: [PATCH] The NAT scripts currently work, but the changes below decrease user error and allow the netmask to be passed in. Signed-off-by: Jon Mason --- tools/examples/vif-nat | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat index f268fdcedc..a86bd91dd9 100644 --- a/tools/examples/vif-nat +++ b/tools/examples/vif-nat @@ -23,7 +23,6 @@ # Exit if anything goes wrong set -e export PATH=/sbin:/bin:/usr/bin:/usr/sbin:$PATH -echo "*vif-nat $*" >&2 # Operation name. OP=$1 @@ -35,17 +34,25 @@ for arg ; do export "${arg}" ; done # Required parameters. Fail if not set. domain=${domain:?} vif=${vif:?} -ip=${ip:?} +ip=${ip:-'169.254.1.1/24'} #if not defined, give a default address -# strip /netmask +echo "*vif-nat $OP domain=$domain vif=$vif ip=$ip" >&2 + +#determine ip address and netmask vif_ip=`echo ${ip} | awk -F/ '{print $1}'` +bits=`echo ${ip} | awk -F/ '{print $2}'` +intmask=$(( ((0xFFFFFFFF << ((32 - $bits)))) & 0xFFFFFFFF )) +netmask=$(( (($intmask & 0xFF000000)) >> 24 )) +netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 )) +netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 )) +netmask=$netmask.$(( $intmask & 0x000000FF )) main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'` # Are we going up or down? case $OP in up) - ifconfig ${vif} ${vif_ip} netmask 255.255.255.0 up + ifconfig ${vif} ${vif_ip} netmask ${netmask} up echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp iptcmd='-A' ipcmd='a' -- 2.30.2